package com.neulogistics.contrib.transfercenter.infrastructure.persistence.repository;

import com.neulogistics.contrib.transfercenter.infrastructure.persistence.orm.service.ITransferOrderPOService;
import com.neulogistics.contrib.transfercenter.domain.model.aggregate.TransferOrder;
import com.neulogistics.contrib.transfercenter.domain.repository.ITransferOrderRepository;
import com.neulogistics.contrib.transfercenter.infrastructure.persistence.converter.TransferOrderEntityPOConverter;
import com.neulogistics.contrib.transfercenter.infrastructure.persistence.orm.po.TransferOrderPO;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class TransferOrderRepository implements ITransferOrderRepository {

    @Resource
    ITransferOrderPOService transferOrderPOService;

    @Override
    public void save(TransferOrder transferOrder) {
        TransferOrderPO transferOrderPO = TransferOrderEntityPOConverter.entityToPO(transferOrder);
        transferOrderPOService.saveOrUpdate(transferOrderPO);
    }

    @Override
    public TransferOrder findById(Long id) {
        TransferOrderPO transferOrderPO = transferOrderPOService.getById(id);
        TransferOrder transferOrder = TransferOrderEntityPOConverter.POToEntity(transferOrderPO);
        return transferOrder;
    }

    @Override
    public void deleteById(Long id) {
        transferOrderPOService.removeById(id);
    }
}
